﻿using Encryption.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Encryption
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        private string pubKey;
        private string privateKey;
        private MyEnum myEnum;
        private string password;
        private Rsa rsa;
        public Window1()
        {
            rsa = new Rsa();
            pubKey = string.Empty;
            privateKey = string.Empty;
            password = string.Empty;
            myEnum = MyEnum.PKCS1;
            InitializeComponent();
            DataObject.AddPastingHandler(textBox, OnPaste);
        }

        public void InitData(string pubKey,string privateKey, MyEnum myEnum, string password)
        {
            this.pubKey = pubKey;
            this.privateKey = privateKey;
            this.myEnum = myEnum;
            this.password = password;
        }

        private void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
            if (!isText) return;

            var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
            textBox.Text = text;
            e.CancelCommand();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text = rsa.RsaEncryptByPublicKey(textBox.Text, pubKey, myEnum); 
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text = rsa.RsaDecodeByPraviteKey(textBox.Text, privateKey, myEnum);
        }
    }
}
